package com.leetcode.concurrency.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Dennis Li
 * @date 2020/8/11 19:08
 */
public class FutureDemo {
    public static void main(String[] args) {
        threadLocalDemo();
    }

    private static void threadLocalDemo(){
        final ThreadLocal<Integer> local1 = new ThreadLocal<>();
        final ThreadLocal<Integer> local2 = new ThreadLocal<>();

        final ExecutorService pool = Executors.newFixedThreadPool(2);

        final Future<?> future1 = pool.submit(() -> {
            local1.set(1);
            local2.set(1);
            System.out.println(local1.get());
            System.out.println(local2.get());
        });

        final Future<?> future2 = pool.submit(() -> {
            System.out.println(local1.get());
            System.out.println(local2.get());
        });

    }

    private static void futureTaskDemo() {
        System.out.println("Thread initialized");
        new Thread(() -> System.out.println("Executed")).start();
        final AtomicInteger integer = new AtomicInteger();
    }
}
